def lagari(fylki):
	hjalp = "ABCD"
	for x in range(5):
		for y in range(5):
			if fylki[x][y] == "XX":
				fylki[x][y] = hjalp[x] + str(y)
			else:
				fylki[x][y] = int(fylki[x][y])
	return fylki

def geneq(fylki):
	jofnur = [["0" for x in range(5)] for x in range(9)]

	for rod in range(4):
		for dalkur in range(5):
			jofnur[rod][dalkur] = fylki[dalkur][rod]

	for dalkur in range(4):
		for rod in range(5):
			jofnur[dalkur+4][rod] = fylki[dalkur][rod]
			
			
	for x in range(5):
		jofnur[8][x] = fylki[x][x]
	
	for x in jofnur:
		for y in range(4):
			if str(x[y]).isdigit():
				x[4] = int(x[4])
				x[4] -= x[y]
				x.pop(y)
	return jofnur


#def reiknirit(jofnur):

	
				




inntak = """XX XX 13 XX 67
3 XX XX XX 37
XX XX XX 11 34
XX 15 XX XX 69
52 48 31 76 38"""

strengir = inntak.splitlines()
ordin = [line.split(' ') for line in strengir]

ordin = lagari(ordin)
print(geneq(ordin))

for x in range(5):
	for y in range(5):
		print(ordin[x][y], end=' ')
	print()
